#include <yatak/yatak.h>
#include <yatak/port.h>

// reboot PS/2
void __reboot()
{
	uint8 temp;
	asm volatile ("cli"); // disable all interrupts 
	// Clear all keyboard buffers (output and command buffers) 
	do
	{
		temp = inportb(KBRD_INTRFC); // empty user data 
		if (CHECK_FLAG(temp, KBRD_BIT_KDATA) != 0)
			inportb(KBRD_IO); // empty keyboard data 
	} while (CHECK_FLAG(temp, KBRD_BIT_UDATA) != 0);
	
	outportb(KBRD_INTRFC, KBRD_RESET); // pulse CPU reset line 
	while (1)		// But if a non maskable interrupt is received, halt again
		asm volatile ("hlt"); // if that didn't work, halt the CPU 
}
